package com.rabbit.eap.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.rabbit.eap.generator.config.GeneratorStrategy;
import com.rabbit.eap.generator.constant.GeneratorConstant;
import com.rabbit.eap.generator.properties.GeneratorProperties;
import org.springframework.stereotype.Component;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.generator
 * @className EapGenerator
 * @author： liyang
 * @version： 1.0
 * @since： 2020/4/29 21:13
 * <p>Description: EapGenerator
 * Eap代码生成器入口类
 * </p>

 */
@Component
public class EapGenerator {
    /**
     * 生成代码
     * @param args
     */
    public static void main(String[] args) {
        GeneratorProperties generatorProperties = new GeneratorProperties();

        // 设置基本信息
        generatorProperties
                .setMavenModuleName("eap-system")
                .setParentPackage("com.rabbit.eap.system")
                .setModuleName("")
                .setAuthor("liyang")
                .setProjectName("eap")
                .setProjectVersion("1.0")
                .setFileOverride(true);

        // 设置表信息
        generatorProperties.setTables(new String[]{
                "sys_config","sys_dept","sys_dict_data",
                "sys_dict_type","sys_login_log","sys_menu",
                "sys_operation_log", "sys_post",
                "sys_role","sys_role_dept","sys_user",
                "sys_role_menu","sys_user_role","sys_user_dept","sys_user_post"});
        // 设置表前缀
        // generatorProperties.setTablePrefix(Arrays.asList("tb_"));

        // 数据源配置
        generatorProperties.getDataSourceConfig()
                .setDbType(DbType.MYSQL)
                .setUsername("root")
                .setPassword("12345678")
                .setDriverName("com.mysql.jdbc.Driver")
                .setUrl("jdbc:mysql://localhost:3306/eap?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true");

        // 生成配置
        generatorProperties.getGeneratorConfig()
                .setGeneratorStrategy(GeneratorStrategy.ALL)
                .setGeneratorEntity(true)
                .setGeneratorController(true)
                .setGeneratorService(true)
                .setGeneratorServiceImpl(true)
                .setGeneratorMapper(true)
                .setGeneratorMapperXml(true)
                .setGeneratorPageParam(true)
                .setGeneratorQueryVo(true)
                .setGeneratorDTO(true)
                .setRequiresPermissions(true)
                .setPageListOrder(true)
                .setParamValidation(true)
                .setSwaggerTags(true)
                .setOperationLog(true);

        // 全局配置
        generatorProperties.getMybatisPlusGeneratorConfig().getGlobalConfig()
                .setOpen(true)
                .setSwagger2(true)
                //开启 BaseResultMap
                .setBaseResultMap(true)
                .setIdType(IdType.AUTO)
                .setDateType(DateType.TIME_PACK);

        // 策略配置
        generatorProperties.getMybatisPlusGeneratorConfig().getStrategyConfig()
                .setNaming(NamingStrategy.underline_to_camel)
                .setColumnNaming(NamingStrategy.underline_to_camel)
                .setEntityLombokModel(true)
                .setEntityTableFieldAnnotationEnable(true)
                .setRestControllerStyle(true)
                .setControllerMappingHyphenStyle(true)
                .setLogicDeleteFieldName(GeneratorConstant.DELETED);

        // 生成代码
        CodeGenerator codeGenerator = new CodeGenerator();
        codeGenerator.generator(generatorProperties);

    }
}
